/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package server.Model;

import server.ClientListener;
import server.View.ServerView;

/**
 * This is the main model for the server
 * @author Richard Irons
 */
public class MainModel {
    private int port = 6881;
    private Thread threadCL;
    private ClientListener clientListener;
    private static MainModel instance;

    private MainModel() {
        clientListener = new ClientListener();
    }
    public static MainModel getInstance() {
        if (instance == null) {
            instance = new MainModel();
        }
        return instance;
    }
    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }
    
    public void startServer() {
        if (clientListener.isRunning()){
        }
        else {
            threadCL = new Thread(clientListener);
            clientListener.startServer();
            threadCL.start();
        }
    }

    public void stopServer() {
        if (clientListener.isRunning()) {
            clientListener.stopServer();
            ServerView.getInstance().addToDisplayArea("Server stopped");
        }
        else
            ServerView.getInstance().addToDisplayArea("Server not running");
    }
}
